from tortoise.models import Model
from tortoise import fields


class Classes(Model):
    class_id = fields.IntField(pk=True)
    class_name = fields.CharField(max_length=32, description="班级名称")
    description = fields.CharField(max_length=255, description="班级描述")

    class Meta:
        table = "classes"


class Students(Model):
    student_id = fields.IntField(pk=True)
    student_name = fields.CharField(max_length=32, description="学生姓名")
    age = fields.IntField(description="学生年龄")
    gender = fields.CharField(max_length=32, description="学生性别")
    class_id = fields.ForeignKeyField("models.Classes", related_name="students")
    course_id = fields.ManyToManyField("models.Courses", related_name="students")

    class Meta:
        table = "students"


class Courses(Model):
    course_id = fields.IntField(pk=True)
    course_name = fields.CharField(max_length=32, description="课程名称")
    credit = fields.CharField(max_length=32, description="课程学分")

    class Meta:
        table = "courses"


class SelectCourse(Model):
    select_id = fields.IntField(pk=True)
    student_id = fields.ForeignKeyField("models.Students", related_name="select_courses")
    course_id = fields.ForeignKeyField("models.Courses", related_name="select_courses")

    class Meta:
        table = "course_selection"


class Score(Model):
    score_id = fields.IntField(pk=True)
    selection_id = fields.ForeignKeyField("models.SelectCourse", related_name="scores")
    midterm_score = fields.FloatField(description="期中成绩")
    final_score = fields.FloatField(description="期末成绩")

    class Meta:
        table = "scores"

